<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资方放款对账 列表</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
			<div class="FXBR">
				<div class="fieldBox ">
					<div class="label">对账日期</div>
					<div class="field">
						<input name="crtTmStart" id="crtTmStart" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
						----
						<input name="crtTmEnd" id="crtTmEnd" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
					</div>
				</div>
			</div>
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	                <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
	                <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
	                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="mcrMonitorCheckGrid" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		// initDatePicker();

		// 日期控件初始化显示
		$('#fileDateStart,#fileDateEnd,#checkTimeStart,#checkTimeEnd').val(currentDate());
	});

	// 日期控件
	function initDatePicker() {

		// ==== 对账日期控件 =====

		//设置开始时间
		$("#fileDateStart").datepicker().on('changeDate', function(e) {
			//获取选取的开始时间
			var endTimeStart =$("#fileDateStart").val();
			//设置结束时间
			$('#fileDateEnd').datepicker('setStartDate', endTimeStart);
		});
		//设置结束时间必须晚于开始时间
		$("#fileDateEnd").datepicker().on('changeDate', function(e) {
			//获取选取的开始时间
			var endTimeStart =$("#fileDateStart").val();
			//设置结束时间
			$('#fileDateEnd').datepicker('setStartDate', endTimeStart);
		});
	}

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}

	// 当前日期格式化展示
	function currentDate() {
		return DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
	}

	//查询按钮事件
	function searchBtn(){
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#mcrMonitorCheckGrid").ligerGrid({
	    	url: '<%=path%>/mcr/mcrMonitorCheck/initList.do',
	    	method : 'post',
	    	isSingleCheck: false,
	    	parms:getSearchParams(),
	        columns: [
				{ display: '上游', width: 100, enabledSort:true, render: function (rowData) {return "公服-卓远";}},
				{ display: '下游',  width: 100, enabledSort:true,render: function (rowData) {return "互联网中心-卓远";}},
	            { display: '对账类型', name: 'dataType', width: 100, enabledSort:true,
                    render: function (rowData) {
                        if (rowData.dataType == 1) {
                            return "人员";
                        } else if (rowData.dataType == 2) {
                            return "账单";
                        } else if (rowData.dataType == 3) {
                            return "状态";
                        } else if (rowData.dataType == 4) {
                            return "合同";
                        }else if (rowData.dataType == 5) {
                            return "流水";
                        } else {
                            return "未知";
                        }
                    }
				},
                { display: '上游总数量', name: 'upCount', width: 150, enabledSort:true,},
				{ display: '下游总数量', name: 'downCount', width: 150, enabledSort:true},
				{ display: '上游总金额', name: 'upAllAmt', width: 100, enabledSort:true},
				{ display: '下游总金额', name: 'downAllAmt', width: 100,enabledSort:true},
				{ display: '是否存在差异', name: 'diffStatus', width: 100, enabledSort:true,
					render:function(rowData){if(rowData.diffStatus==1){return "是";}else{return "否";}}
				},
				{ display: '差异笔数', name: 'diffCount', width: 100, enabledSort:true,},
				{ display: '差异金额(元)', name: 'diffAmt', width: 150, enabledSort:true,},
				{ display: '对账状态', name: 'state', width: 100, enabledSort:true,
					render:function(rowData){
					if(rowData.state=="1"){
						return "完成对账";
					}else if (rowData.state=="0"){
						return "未完成对账";
					}
				}
				},
				{ display: '对账完成时间', name: 'crtTm', width: 150, render:renderDate, enabledSort:true,},
				getGridOperColumnContent()
			],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:false,
	        rownumbers:true
	    });
	    grid = liger.get("mcrMonitorCheckGrid");
	    grid.setHeight(100);
	}

  	//Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
				render: function (rowdata, rowindex, value) {
                	//人员信息不需要下载
					if(rowdata.dataType !="1"){
						return '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="exportFile(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>下载</a>';
					}
				}
            }
    	return data;
	}

	function exportFile(id) {
		var req = "id="+id;
		window.location.href="<%=path%>/mcr/mcrMonitorCheck/exportFile.do?"+req;
	}

	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "crtTmStart":"",
		    "crtTmEnd":""
		  });
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
</script>

</body>
</html>